﻿namespace ComputationalCore.Helper
{
    public static class CalculateHelper
    {
        public delegate double Function(double x);

        public static double Integrate(this Function func, double eps, double from, double to)
        {
            double sum = 0;
            double square = (to - from) * (func(to) + func(from)) / 2;
            if (square >= eps)
            {
                sum = Integrate(func, eps, from, (to + from) / 2) +
                        Integrate(func, eps, (to + from) / 2, to);
            }
            else
            {
                sum = square;
            }
            return sum;
        }
    }
}
